define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'schedule/index' + location.search,
                    add_url: 'schedule/add',
                    edit_url: 'schedule/edit',
                    del_url: 'schedule/del',
                    multi_url: 'schedule/multi',
                    import_url: 'schedule/import',
                    table: 'schedule',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'film.name', title: __('Film_info_id'),operate: false},
                        // {field: 'hall_id', title: __('Hall_id'),operate: false},
                        {field: 'hall_id', title: __('Hall_id'),visible: false, searchList: $.getJSON("hall/ajaxselect"), operate: 'FIND_IN_SET', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'hall.name', title: __('Hall_id'), operate: false },
                        {field: 'des', title: __('Des'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'date', title: __('Date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'start_time', title: __('Start_time'),operate: false},
                        // {field: 'end_time', title: __('End_time'),operate: false},
                        {field: 'reservationsNum', title: __('已预约人数'),operate: false},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"0":__('Status 0')}, formatter: Table.api.formatter.status},
                        {field: 'operating_status', title: __('Operating_status'), searchList: {"0":__('Operating_status 0'),"1":__('Operating_status 1'),"2":__('Operating_status 2')}, formatter: Table.api.formatter.status},
                        {field: 'seat_normal_show_price', title: __('Seat_normal_show_price'), operate:false},
                        {field: 'seat_normal_price', title: __('Seat_normal_price'), operate:false},
                        // {field: 'seat_special_price', title: __('Seat_special_price'), operate:'BETWEEN'},
                        {field: 'seat_vip_show_price', title: __('Seat_vip_show_price'), operate:false},
                        {field: 'seat_vip_price', title: __('Seat_vip_price'), operate:false},
                        {field: 'is_wine_menu', title: __('Is_wine_menu'), searchList: {"1":__('Is_wine_menu 1'),"0":__('Is_wine_menu 0')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons: [
                            {
                                name: 'occupy',
                                text: __('占座'),
                                title: __('占座'),
                                classname: 'btn btn-xs btn-primary btn-dialog',
                                icon: 'fa fa-cart-arrow-down',
                                url:function (row,column) {
                                    return 'hall/hall/#/buy/ids/'+row.id;
                                },
                                extend: 'data-area=["1230px","760px"]',
                                callback: function (data) {
                                    Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                },
                                visible: function (row) {
                                    //返回true时按钮显示,返回false隐藏
                                    return true;
                                }
                            },
                        ]}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'schedule/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'schedule/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'schedule/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
